//
//  VOCMemoryListController.m
//  iVoc
//
//  Created by Wallace Wu on 09-4-7.
//  Copyright 2009 Sonic Solutions. All rights reserved.
//

#import "VOCMemoryListController.h"
#import "VOCMemoryViewController.h"


@implementation VOCMemoryListController

- (id)initWithNibName:(NSString *)nibName bundle:(NSBundle *)nibBundle
{
    self = [super initWithNibName:nibName bundle:nibBundle];
    if (self) {
        
        self.title = NSLocalizedString(@"MEMORY",nil);
        rememberWord = YES;
        self.tabBarItem.image = [UIImage imageNamed:@"memory.png"];
    }
    return self;
}

-(void)changeMemoryPref:(id)sender
{
    if(rememberWord)
    {
        rememberWord = NO;
        self.navigationItem.rightBarButtonItem.title = NSLocalizedString(@"MEM_DEFINITION",nil);
    }
    else
    {
        rememberWord = YES;
        self.navigationItem.rightBarButtonItem.title = NSLocalizedString(@"MEM_WORD",nil);
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
    self.navigationItem.title = NSLocalizedString(@"MEMORY",nil);
    
    self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"MEM_WORD",nil) style:UIBarButtonItemStyleBordered target:self action:@selector(changeMemoryPref:)] autorelease];
    
}

 
/*
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
}
*/

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
    // Release anything that's not essential, such as cached data
}

#pragma mark Table view methods

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [super tableView:tableView didSelectRowAtIndexPath:indexPath];
    
    if(selectedList.data.count == 0)
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"WARNING",nil) 
                                                        message:NSLocalizedString(@"EMPTY_WORD_LIST",nil) 
                                                       delegate:nil
                                              cancelButtonTitle:NSLocalizedString(@"OK",nil) 
                                              otherButtonTitles:nil];
        [alert show];
        [alert release];
        
        return;
    }
    // Navigation logic may go here. Create and push another view controller.
	VOCMemoryViewController *memmoryViewController = [[VOCMemoryViewController alloc] initWithNibName:@"VOCMemoryViewController" bundle:nil];
    memmoryViewController.rememberWord = rememberWord;
    memmoryViewController.wordList = selectedList;
	[self.navigationController pushViewController:memmoryViewController animated:YES];
	[memmoryViewController release];
}


/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/


/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
    }   
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/


/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/


/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/


- (void)dealloc {
    [super dealloc];
}


@end

